#encoding=utf-8
'''
Created on 2015-3-29

@author: cooler
'''
import sys,os
reload(sys)
sys.setdefaultencoding('utf8')

import  logging,  os.path
import math, time
from datetime import datetime, timedelta
import math,re
import traceback

from utils import Redisfactory
from service.models import *


from flask import Blueprint, jsonify, render_template, make_response, request, redirect,url_for, session, abort, current_app
from flask import g
from flask_principal import Principal, Permission, UserNeed, RoleNeed, Identity, AnonymousIdentity, identity_changed, identity_loaded



home = Blueprint('home', __name__)


# logger.info("")

#----  全局变量，过期时间
EXPIRE_TIME = 60*2
EXPIRE_TIME_TOKEN = 60*60*24*15
EXPIRE_TIME_PHONE_CODE = 60*10
EXPIRE_TIME_USERINFO = 60*60*24*15
EXPIRE_TIME_PASSWORD_WRONG = 10*60

logger = logging.getLogger('home')
logger.setLevel(logging.DEBUG)
WHITELIST = ['/home/']

@home.before_request
def before_request():
    g.HEADERS =  request.headers
    logger.info("method:"+str(request.method))
    g.args = request.args if request.method == 'GET' else request.form
    logger.info("request.path:"+request.path+",g.args:"+str(g.args))
            
    

            
@home.teardown_request
def teardown_request(exception):
    # g.session.close()
    pass

@home.errorhandler(404)
def page_not_found(error):
    return render_template('404.html'), 404

@home.route("/",methods=['POST','GET'])
def index():
    user = User.objects().first()
    res = {
        "user_list":g.args,
        "user":user,
    }   
    return jsonify(res)

###############    interface   ########################

#----------------------------------------------------------------------------------------------------------------------------------------



